! dmitry.konovalov @ jcu.edu.au
module func_lgrr; 
use dbg;
use func_arr_mod;
use func_factory;
implicit none; 
logical, save :: FUNC_LGRR_TRACE_ENTRY = .TRUE.;
 

type LGRR_OPT_T  ! Laguerre options
  real(R14) :: alpha; 
  real(R14) :: lambda;
  real(R14), pointer :: xp(:), quard(:);
  integer :: n; 
end type

contains


! Note: xp is shared
function new_lgrr_arr(opt) result(res);  
  implicit none;  
  type(LGRR_OPT_T), intent(IN):: opt; 
  type(FUNC_ARR_T), pointer :: res; 
  integer :: status, i, maxi, mini;
  type(FUNC_VEC_T), pointer :: py;
  call dbg_info("-->new_lgrr_arr()", FUNC_LGRR_TRACE_ENTRY);
  res => new_func_arr(opt%xp, opt%n);

  mini = LBOUND(res%fa, 1);
  maxi = UBOUND(res%fa, 1);
  if (opt%n == 0) return;
  if (opt%n == 1) then
    py => new_func_polynom(opt%xp, (/D1/) );
    call set_func_py(res%fa(mini)%fp, py); ! free old memory
    return;
  end if 
  if (opt%n == 2) then
!  TODO
    py => new_func_polynom(opt%xp, (/D1/) );
    call set_func_py(res%fa(mini+1)%fp, py); ! free old memory
    return;
  end if 
  return;
end function



end module 